package com.example.myapplication.tack_29.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.tack_29.adapter.DeliverAdapter;
import com.example.myapplication.tack_29.data.DeliverData;
import com.example.myapplication.utils.OkHttpTool;

public class RecordFragment extends Fragment {
    private View view;
    private Handler handler;
    private RecyclerView deliver;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.tack_29_fragment_record, container, false);
        init();
        getDeliver();
        return view;
    }

    private void getDeliver() {
        String url = "prod-api/api/job/deliver/list?pageSize=10&pageNum=1";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, DeliverData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                DeliverData deliverData = (DeliverData)obj;
                if(deliverData.getCode() == 200){
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            deliver.setLayoutManager(new LinearLayoutManager(RecordFragment.this.getContext()));
                            deliver.setAdapter(new DeliverAdapter(deliverData.getRows(),RecordFragment.this.getContext()));
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void init() {
        handler = new Handler();
        deliver = view.findViewById(R.id.deliver);
    }
}